<template>
  <div>
    <!-- 视频区域 -->
    <div class="videos">
      <video src="@/assets/video/homepage.mp4" loop muted autoplay></video>
    </div>
    <div class="body">
      <div>
        <img class="svg" src="../assets/svg/iaaiscolor.svg" />
      </div>
      <!-- 登陆区域 -->
      <div class="Login">
        <el-form class="login-container">
          <h1 v-if="registerForm.type === 0" class="title">用户注册</h1>
          <h1 v-if="registerForm.type === 1" class="title">企业注册</h1>
          <el-form-item label="注册类型" prop="type">
            <el-radio-group v-model="registerForm.type">
              <el-radio :label="0">个人注册</el-radio>
              <el-radio :label="1">公司注册</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- 个人注册 -->
          <el-form-item v-if="registerForm.type === 0">
            <el-input
              type="type"
              placeholder="手机账号"
              v-model="registerForm.phone"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 0">
            <el-input
              type="type"
              placeholder="密码"
              v-model="registerForm.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 0">
            <el-input
              type="type"
              placeholder="邀请码(选填)"
              v-model="registerForm.invitationcode"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 0">
            <el-input
              v-model="registerForm.code"
              autocomplete="off"
              placeholder="验证码"
              prefix-icon="el-icon-phone"
            >
              <el-button
                slot="append"
                style="color: white; background-color: #1890ff"
                v-show="showTime"
                @click="sendEmail(registerForm.phone)"
                >发送验证码</el-button
              >
              <el-button
                slot="append"
                style="
                  color: white;
                  background-color: #1890ff;
                  margin-left: -20px;
                "
                v-show="!showTime"
                >{{ sendTime }}秒</el-button
              >
            </el-input>
            <el-form-item class="button1">
            <el-button type="primary" @click="personRegister()" style="width: 48%"
              >注册</el-button
            >
            <el-button type="primary" @click="toLogin()" style="width: 48%"
              >返回</el-button
            >
          </el-form-item>
          </el-form-item>
          <!-- 企业注册 -->
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              type="type"
              placeholder="统一信用代码"
              v-model="registerForm.creditCode"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              type="type"
              placeholder="注册人身份证号码"
              v-model="registerForm.idCard"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              type="type"
              placeholder="手机号码"
              v-model="registerForm.phone"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              type="type"
              placeholder="密码"
              v-model="registerForm.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              type="type"
              placeholder="邀请码(选填)"
              v-model="registerForm.invitationcode"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item v-if="registerForm.type === 1">
            <el-input
              v-model="registerForm.code"
              autocomplete="off"
              placeholder="验证码"
              prefix-icon="el-icon-phone"
            >
              <el-button
                slot="append"
                style="color: white; background-color: #1890ff"
                v-show="showTime"
                @click="sendEmail(registerForm.phone)"
                >发送验证码</el-button
              >
              <el-button
                slot="append"
                style="
                  color: white;
                  background-color: #1890ff;
                  margin-left: -20px;
                "
                v-show="!showTime"
                >{{ sendTime }}秒</el-button
              >
            </el-input>
            <el-form-item class="button1">
            <el-button type="primary" @click="doRegister()" style="width: 48%"
              >注册</el-button
            >
            <el-button type="primary" @click="toLogin()" style="width: 48%"
              >返回</el-button
            >
          </el-form-item>
          </el-form-item>
         
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { putCode } from '@/http/api';
export default {
    name: "Register",
  data: function () {
    return {
      registerForm: {
        type: 0, // 注册类型，0表示个人注册，1表示公司注册
        phone: "", // 手机号
        code: "", // 手机验证码
        password: "", // 密码
        creditCode: "", // 企业信用代码
        idCard: "", // 法人身份证号码
        contactPhone: "", // 法人手机号
        companyName: "", // 企业名称
        invitationcode:''
      },
      showTime: true /* 布尔值，通过v-show控制显示‘获取按钮’还是‘倒计时’ */,
      sendTime: "" /* 倒计时 计数器 */,
      timer: null,
    };
  },
  methods: {
    doRegister: function () {},
    toLogin: function () {
      this.$router.push("/");
    },
    sendEmail() {
      if (this.registerForm.phone === "" || this.registerForm.phone == null) {
        this.$message({
          duration: 1000,
          message: "手机号不能为空！",
          type: "false",
        });
        this.registerForm.phone = "";
      } else {
        const TIME_COUNT = 60; //  更改倒计时时间
        if (!this.timer) {
          this.sendTime = TIME_COUNT;
          this.showTime = false;
          this.timer = setInterval(() => {
            if (this.sendTime > 0 && this.sendTime <= TIME_COUNT) {
              this.sendTime--;
            } else {
              this.showTime = true;
              clearInterval(this.timer); // 清除定时器
              this.timer = null;
            }
          }, 1000);
          const data = {
            phone: this.registerForm.phone,
          };
          putCode(data).then((res) => {
            console.log(res);
            this.code1 = res.data;
          });
        }
      }
    },
    personRegister(){
      
    },
  },
};
</script>

<style lang="less" scoped>
.videos {
  background-color: rgba(163, 169, 169, 0.8);
  position: absolute;
  width: 100%;
  height: 100%;

  video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
  }
}

.svg {
  width: 400px;
  opacity: 0.7;
}
.body {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 800px;
}



.login-wrap {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-top: 10%;
  /* background-color: #112346; */
  background-repeat: no-repeat;
  background-position: center right;
  background-size: 100%;
}

.login-container {
  border-radius: 10px;
  margin: 90px auto;
  width: 350px;
  padding: 30px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  text-align: left;
  box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
  opacity: 0.9;
}

.title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
  opacity: 0.9;
}
.button1{
  margin-top: 20px;
}
</style>